import java.util.Arrays;

public class text {
    public static void main(String[] args) {
        //遍历二维数组
        int[][] arr={{1,2,3},{4,5,6}};
        //法一：
        for (int i = 0; i < arr.length; i++) {
            for (int j = 0; j < arr[i].length; j++) {
                System.out.print(arr[i][j]+" ");
            }
            System.out.println();
        }
        System.out.println("=========");
        //法二：
        for(int[] temp : arr){
            for(int x : temp){
                System.out.print(x+" ");
            }
            System.out.println();
        }
        //法三：
        String ret=Arrays.deepToString(arr);
        System.out.println(ret);
    }

    public static void main3(String[] args) {
        //数组逆序
        int[] arr = {1,2,3,4,5,6};
        reverseArray(arr);
        System.out.println(Arrays.toString(arr));
    }
    public static void reverseArray(int[] arr){
        int i=0;
        int j= arr.length-1;
        while (i<j){
            int temp = arr[i];
            arr[i]=arr[j];
            arr[j]=temp;
            i++;
            j--;
        }
    }
    public static void main2(String[] args) {
        //数组拷贝
        int[] arr={1,2,3,4,5,6};
        //法一：利用copyOf
        int[] ret1 = Arrays.copyOf(arr,arr.length);
        System.out.println(Arrays.toString(ret1));
        System.out.println("==================");
        //法二：自己调用函数
        int[] ret2 = copy(arr);
        System.out.println(Arrays.toString(ret2));

    }
    public static int[] copy(int[] arr){
        int[] copyArr = new int[arr.length];
        for (int i = 0; i < arr.length; i++) {
            copyArr[i]=arr[i];
        }
        return copyArr;
    }
    public static void main1(String[] args) {
        //数组排序
        int[] arr={3,2,6,8,10,7,4};
        //法一：直接用sort
        Arrays.sort(arr);
        System.out.println(Arrays.toString(arr));
        //法二：冒泡排序
         bubbleSort(arr);
        System.out.println(Arrays.toString(arr));

    }

    public static void bubbleSort(int[] arr){
        for (int i = 0; i < arr.length-1; i++) {
            boolean falg = false;
            for (int j = 0; j < arr.length-1; j++) {
                if(arr[j]>arr[j+1]){
                    int temp = arr[j];
                    arr[j]=arr[j+1];
                    arr[j+1]=temp;
                    falg = true;
                }
            }
            if(falg == false){
                break;
            }

        }
    }

}
